﻿using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UMLSynthesizer.CSharpAnalyzer.Elements;
using UMLSynthesizer.LangAnalyzer.Elements;
using UMLSynthesizer.LangAnalyzer.ExtensionMethods;

namespace UMLSynthesizer.CSharpAnalyzer.Helpers
{
    class CSharpElementWithHeritageHelper
    {
        #region Fields

        CSharpProjectElement project;
        IEnumerable<SyntaxNode> elementNodes;

        #endregion

        #region Constructors

        public CSharpElementWithHeritageHelper(CSharpProjectElement project, SyntaxNode elementNode)
            : this(project, new SyntaxNode[] { elementNode }) { }
        public CSharpElementWithHeritageHelper(CSharpProjectElement project, IEnumerable<SyntaxNode> elementNodes)
        {
            this.project = project;
            this.elementNodes = elementNodes;
        }

        #endregion

        #region Properties

        public IEnumerable<IElementWithHeritageBase> BaseList
        {
            get
            {
                return (from elementNode in
                            (from elementNode in elementNodes
                             where (elementNode as BaseTypeDeclarationSyntax).BaseList != null
                             select elementNode)
                        from typeSyntax in (elementNode as BaseTypeDeclarationSyntax).BaseList.Types
                        select project.GetTypeReference(typeSyntax) as IElementWithHeritageBase)
                            .OrderBy(element => element.GetDefinitionPath())
                            .Distinct();
            }
        }

        #endregion
    }
}
